#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

const int kMaxN = 2e3 + 10;
const int kMaxM = 2e3 + 10;
const int kInf = 1e9;

int dis[kMaxN][kMaxM];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
char output[] = "DURL";
vector<string> g;

bool Check(int x, int y, int n, int m) {
  return x >= 0 && x < n && y >= 0 && y < m;
}

void BFS(int n, int m) {
  queue<pair<int, int>> que;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dis[i][j] = kInf;
    }
  }
  que.emplace(n - 1, m - 1);
  dis[n - 1][m - 1] = 0;

  for (; !que.empty(); que.pop()) {
    int x = que.front().first, y = que.front().second;

    for (int i = 0; i < 4; i++) {
      int nx = x + dir[i][0], ny = y + dir[i][1];

      if (Check(nx, ny, n, m) && dis[nx][ny] == kInf && g[x][y] != g[nx][ny]) {
        dis[nx][ny] = dis[x][y] + 1;
        que.emplace(nx, ny);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;

  for (cin >> T; T; T--) {
    int n, m;

    cin >> n >> m;

    g.resize(n, "");
    for (int i = 0; i < n; i++) {
      cin >> g[i];
    }

    BFS(n, m);
    if (dis[0][0] == kInf) {
      cout << -1 << "\n";
    } else {
      cout << dis[0][0] << "\n";
      int nowx = 0, nowy = 0;

      while (nowx != n - 1 || nowy != m - 1) {
        for (int i = 0; i < 4; i++) {
          int nx = nowx + dir[i][0], ny = nowy + dir[i][1];
          if (Check(nx, ny, n, m) && dis[nx][ny] + 1 == dis[nowx][nowy]) {
            nowx = nx;
            nowy = ny;
            cout << output[i];
            break;
          }
        }
      }
      cout << "\n";
    }
  }
  return 0;
}